package com.soboot.handler;

import com.soboot.base.util.ResponseUtil;
import com.soboot.response.Result;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:
 * @createTime: 2022年09月20日 13:15:22
 * @version:
 * @Description:
 * @Copyright:
 */
public class BaseAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {

        ResponseUtil.writeResponse(
                MediaType.APPLICATION_JSON_VALUE,
                HttpServletResponse.SC_UNAUTHORIZED, Result.fail(HttpServletResponse.SC_UNAUTHORIZED, "无效的Token"),httpServletResponse);
    }
}
